home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
ddj0897.zip
/
DYN401.ZIP
/
dpp
/
proto.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-16
|
14KB
|
541 lines
/* Copyright (c) 1993-1996 Algorithms Corporation */
/* All rights reserved. */
/* This file automatically generated by dpp - do not edit */
#define DPP_STRATEGY 2
#define DPP_FASTWIDE 0
#line 16 "proto.d"
#include <ctype.h>
#include <string.h>
#include "dpp.h"
#define CLASS Prototype_c
#define ivType Prototype_iv_t
#include "generics.h"
object Prototype_c;
#line 31 "proto.c"
typedef struct _Prototype_iv_t {
object iName;
object iFixedName;
object iRtn;
object iArgs;
object iProto;
object iParams;
int iVararg;
int iException;
int iNeedRest;
object iLastArg;
} Prototype_iv_t;
#line 36 "proto.d"
#define strne(a, b) strcmp(a, b)
#define streq(a, b) !strcmp(a, b)
#define istart(x) (isalpha(x) || (x) == '_')
#define irest(x) (isalnum(x) || (x) == '_')
extern char *trunc_mname(char *mname);
cmeth objrtn Prototype_cm_gNew(object self)
{
return gShouldNotImplement(self, "gNew");
}
cmeth objrtn Prototype_cm_gNewWithStrStr(object self, char *nm, char *rt)
{
object obj = oSuper(Prototype_c, gNew, self)(self);
ivType *iv = ivPtr(obj);
iv->iName = gNewWithStr(String, nm);
iv->iRtn = gNewWithStr(String, rt);
return obj;
}
imeth objrtn Prototype_im_gDispose(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
gDispose(iv->iName);
if (iv->iFixedName)
gDispose(iv->iFixedName);
gDispose(iv->iRtn);
if (iv->iArgs)
gDeepDispose(iv->iArgs);
if (iv->iProto)
gDeepDispose(iv->iProto);
if (iv->iParams)
gDeepDispose(iv->iParams);
if (iv->iLastArg)
gDeepDispose(iv->iLastArg);
return oSuper(Prototype_c, gDispose, self)(self);
}
imeth int Prototype_im_gHash(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return gHash(iv->iName);
}
imeth int Prototype_im_gCompare(object self, object obj)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
ChkArgTyp(obj, 2, CLASS);
return gCompare(iv->iName, ivPtr(obj)->iName);
}
static void remove_variable(char *buf, char *var)
{
register int i, vi = -1;
for (i=0 ; buf[i] ; )
if (istart(buf[i])) {
vi = i++;
while (buf[i] && irest(buf[i]))
i++;
} else
i++;
if (vi >= 0) {
for (i=vi ; irest(buf[i]) ; )
*var++ = buf[i++];
if (vi && buf[vi-1] == ' ')
vi--;
for (i=vi+1 ; buf[i] && irest(buf[i]) ; i++);
memmove(buf+vi, buf+i, strlen(buf+i) + 1);
}
*var = '\0';
}
static void make_proto(ivType *iv, object ar)
{
object seq, nxt, prv=NULL;
char buf[100], var[50];
iv->iProto = gNew(LinkObject);
iv->iParams = gNew(LinkObject);
for (seq=gSequence(ar) ; nxt = gNext(seq) ; ) {
strcpy(buf, gStringValue(nxt));
remove_variable(buf, var);
gAddLast(iv->iProto, gNewWithStr(String, buf));
if (!*var) {
iv->iNeedRest = 1;
if (iv->iLastArg)
DISPOSE(iv->iLastArg);
iv->iLastArg = prv ? gCopy(prv) : prv;
}
gAddLast(iv->iParams, prv=gNewWithStr(String, *var ? var : "_rest_"));
}
}
imeth objrtn Prototype_im_gPrintArgs(object self, object fobj)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
object seq, nxt;
int n=0;
if (iv->iArgs && !iv->iVararg && !iv->iException)
for (seq=gSequence(iv->iArgs) ; nxt = gNext(seq) ; ) {
if (n++)
gPuts(fobj, ", ");
gPuts(fobj, (char *) nxt);
}
else
gPuts(fobj, "object self, ...");
return self;
}
imeth objrtn Prototype_im_gPrintFixedArgs(object self, object fobj)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
object seq, nxt;
int n=0;
if (iv->iArgs)
for (seq=gSequence(iv->iArgs) ; nxt = gNext(seq) ; ) {
if (n++)
gPuts(fobj, ", ");
gPuts(fobj, (char *) nxt);
}
else
gPuts(fobj, "object self, ...");
return self;
}
imeth objrtn Prototype_im_gPrintMethArgs(object self, object fobj, int Strategy, int vararg)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
object seq, nxt;
int n=0;
if (vararg && Strategy != 1) {
gPut(fobj, gNewToken(Token, "object self", 0L, 0));
gPut(fobj, gNewToken(Token, ",", 0L, 1));
gPut(fobj, gNewToken(Token, "va_list _rest_", 0L, 0));
} else if (iv->iArgs)
for (seq=gSequence(iv->iArgs) ; nxt = gNext(seq) ; ) {
if (n++)
gPut(fobj, gNewToken(Token, ",", 0L, 1));
if (Strategy > 1 && streq(gStringValue(nxt), "..."))
gPut(fobj, gNewToken(Token, "va_list _rest_", 0L, 0));
else
gPut(fobj, gNewToken(Token, gStringValue(nxt), 0L, 0));
}
gPut(fobj, gNewToken(Token, ")", 0L, 0));
return self;
}
imeth objrtn Prototype_im_gPrintVars(object self, object fobj)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
object seq, nxt;
int n=0;
char *v;
if (iv->iParams && !iv->iVararg && !iv->iException)
for (seq=gSequence(iv->iParams) ; nxt = gNext(seq) ; ) {
if (n++)
gPuts(fobj, ", ");
v = gStringValue(nxt);
if (*v)
gPuts(fobj, (char *) nxt);
else
gPuts(fobj, "_rest_");
}
else
gPuts(fobj, "self, _rest_");
return self;
}
imeth objrtn Prototype_im_gUseVars(object self, object fobj)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
object seq, nxt;
char *v;
int n = 0;
if (!iv->iParams)
return self;
for (seq=gSequence(iv->iParams) ; nxt = gNext(seq) ; )
if (n++) {
v = gStringValue(nxt);
if (*v && strne(v, "_rest_"))
vPrintf(fobj, "\tUSE(%s);\n", v);
}
return self;
}
#if 0
static void print_args(ivType *iv, object ar)
{
object seq, nxt;
int n=0;
vPrintf(stdoutStream, "%s %s(", gStringValue(iv->iRtn), gStringValue(iv->iName));
for (seq=gSequence(ar) ; nxt = gNext(seq) ; ) {
if (n++)
gPuts(stdoutStream, ", ");
gPuts(stdoutStream, (char *) nxt);
}
gPuts(stdoutStream, ")\n");
if (iv->iVararg)
gPuts(stdoutStream, "Varargs is set\n");
else
gPuts(stdoutStream, "Varargs is not set\n");
if (iv->iException)
gPuts(stdoutStream, "Exception is set\n");
else
gPuts(stdoutStream, "Exception is not set\n");
}
#endif
imeth objrtn Prototype_im_gSetArgs(object self, object ar)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
if (iv->iArgs)
DEEPDISPOSE(iv->iArgs);
if (iv->iProto)
iv->iProto = DEEPDISPOSE(iv->iProto);
if (iv->iParams)
iv->iParams = DEEPDISPOSE(iv->iParams);
if (iv->iArgs = ar)
make_proto(iv, ar);
if (ar && gSize(ar) == 2 && streq(gStringValue(gLast(ar)), "..."))
iv->iVararg = 1;
#if 0
print_args(iv, iv->iArgs);
print_args(iv, iv->iProto);
#endif
return self;
}
imeth objrtn Prototype_im_gReturnType(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iRtn;
}
imeth objrtn Prototype_im_gArgs(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iArgs;
}
imeth objrtn Prototype_im_gPrototype(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iProto;
}
imeth objrtn Prototype_im_gParameters(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iParams;
}
imeth objrtn Prototype_im_gDeepCopy(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
object nobj;
ivType *niv;
nobj = oSuper(Prototype_c, gDeepCopy, self)(self);
niv = ivPtr(nobj);
niv->iName = gDeepCopy(iv->iName);
niv->iFixedName = iv->iFixedName ? gDeepCopy(iv->iFixedName) : iv->iFixedName;
niv->iRtn = gDeepCopy(iv->iRtn);
if (iv->iArgs) {
niv->iArgs = gDeepCopy(iv->iArgs);
niv->iProto = gDeepCopy(iv->iProto);
niv->iParams = gDeepCopy(iv->iParams);
}
if (iv->iLastArg)
niv->iLastArg = gDeepCopy(iv->iLastArg);
return nobj;
}
imeth int Prototype_im_gMatchNoError(object self, object mproto)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
ivType *miv = ivPtr(mproto);
object mseq, gseq, garg, marg;
#if 0
print_args(iv, iv->iArgs);
print_args(miv, miv->iArgs);
#endif
if (gCompare(miv->iRtn, iv->iRtn))
return 0;
if ((!miv->iArgs || miv->iVararg || miv->iException) && (!iv->iArgs || iv->iVararg))
return 1;
if (miv->iException || !miv->iArgs || miv->iVararg || !iv->iArgs || iv->iVararg)
return 0;
if (gSize(miv->iArgs) != gSize(iv->iArgs))
return 0;
mseq = gSequence(miv->iArgs);
gseq = gSequence(iv->iArgs);
garg = (object) 1;
while (marg = gNext(mseq)) {
garg = gNext(gseq);
if (!garg || gCompare(marg, garg)) {
DISPOSE(mseq);
if (garg)
DISPOSE(gseq);
return 0;
}
}
if (garg)
DISPOSE(gseq);
return 1;
}
imeth int Prototype_im_gMatch(object self, object mproto)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
ivType *miv = ivPtr(mproto);
object mseq, gseq, garg, marg;
int n, error=0;
#if 0
print_args(iv, iv->iArgs);
print_args(miv, miv->iArgs);
#endif
if (gCompare(miv->iRtn, iv->iRtn)) {
error = 1;
vPrintf(stdoutStream, "Method %s and generic %s have different return types\n",
trunc_mname(gStringValue(miv->iName)),
gStringValue(iv->iName));
}
if (iv->iException || miv->iVararg && iv->iVararg)
return error;
if (miv->iVararg || iv->iVararg) {
vPrintf(stdoutStream, "Method %s and generic %s have different arguments\n",
trunc_mname(gStringValue(miv->iName)),
gStringValue(iv->iName));
return 1;
}
if (!miv->iProto) {
vPrintf(stdoutStream, "Warning: Method %s has no prototype.\n",
trunc_mname(gStringValue(miv->iName)));
return error;
}
if (!iv->iProto)
return error;
if (gSize(miv->iProto) != gSize(iv->iProto)) {
vPrintf(stdoutStream, "Method %s and generic %s have a different number of arguments\n",
trunc_mname(gStringValue(miv->iName)),
gStringValue(iv->iName));
return 1;
}
mseq = gSequence(miv->iProto);
gseq = gSequence(iv->iProto);
garg = (object) 1;
for (n=1 ; marg = gNext(mseq) ; ++n) {
garg = gNext(gseq);
if (!garg) {
error = 1;
vPrintf(stdoutStream, "Method %s and generic %s have a different number of arguments.\n",
trunc_mname(gStringValue(miv->iName)),
gStringValue(iv->iName));
break;
}
#line 409 "proto.d"
if (gCompare(marg, garg)) {
error = 1;
vPrintf(stdoutStream, "Method %s and generic %s have different argument types (%d)\n",
trunc_mname(gStringValue(miv->iName)),
gStringValue(iv->iName), n);
}
}
if (marg)
DISPOSE(mseq);
if (garg)
DISPOSE(gseq);
return error;
}
imeth objrtn Prototype_im_gGetMGName(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iName;
}
imeth objrtn Prototype_im_gChangeName(object self, char *nm)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
if (iv->iName)
gChangeStrValue(iv->iName, nm);
else
iv->iName = gNewWithStr(String, nm);
return self;
}
imeth objrtn Prototype_im_gGetFixedName(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iFixedName;
}
imeth objrtn Prototype_im_gChangeFixedName(object self, char *nm)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
if (iv->iFixedName)
gChangeStrValue(iv->iFixedName, nm);
else
iv->iFixedName = gNewWithStr(String, nm);
return self;
}
imeth objrtn Prototype_im_gVarArg(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
iv->iVararg = 1;
return self;
}
imeth int Prototype_im_gIsVarArg(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iNeedRest || iv->iVararg;
}
imeth char * Prototype_im_gLastArg(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
return iv->iLastArg && !iv->iVararg ? gStringValue(iv->iLastArg) : "self";
}
imeth objrtn Prototype_im_gException(object self)
{ Prototype_iv_t *iv = GetIVs(Prototype, self);
iv->iException = 1;
return self;
}
#line 483 "proto.c"
objrtn Prototype_initialize(void)
{
static CRITICALSECTION cs;
static int volatile once = 0;
ENTERCRITICALSECTION(_CI_CS_);
if (!once) {
INITIALIZECRITICALSECTION(cs);
once = 1;
}
LEAVECRITICALSECTION(_CI_CS_);
ENTERCRITICALSECTION(cs);
if (Prototype_c) {
LEAVECRITICALSECTION(cs);
return Prototype_c;
}
INHIBIT_THREADER;
Prototype_c = gNewClass(Class, "Prototype", sizeof(Prototype_iv_t), 0, END);
cMethodFor(Prototype, gNew, Prototype_cm_gNew);
cMethodFor(Prototype, gNewWithStrStr, Prototype_cm_gNewWithStrStr);
iMethodFor(Prototype, gMatch, Prototype_im_gMatch);
iMethodFor(Prototype, gChangeFixedName, Prototype_im_gChangeFixedName);
iMethodFor(Prototype, gLastArg, Prototype_im_gLastArg);
iMethodFor(Prototype, gChangeName, Prototype_im_gChangeName);
iMethodFor(Prototype, gArgs, Prototype_im_gArgs);
iMethodFor(Prototype, gMatchNoError, Prototype_im_gMatchNoError);
iMethodFor(Prototype, gPrintMethArgs, Prototype_im_gPrintMethArgs);
iMethodFor(Prototype, gGetFixedName, Prototype_im_gGetFixedName);
iMethodFor(Prototype, gGetMGName, Prototype_im_gGetMGName);
iMethodFor(Prototype, gCompare, Prototype_im_gCompare);
iMethodFor(Prototype, gPrototype, Prototype_im_gPrototype);
iMethodFor(Prototype, gPrintVars, Prototype_im_gPrintVars);
iMethodFor(Prototype, gSetArgs, Prototype_im_gSetArgs);
iMethodFor(Prototype, gDispose, Prototype_im_gDispose);
iMethodFor(Prototype, gPrintArgs, Prototype_im_gPrintArgs);
iMethodFor(Prototype, gParameters, Prototype_im_gParameters);
iMethodFor(Prototype, gPrintFixedArgs, Prototype_im_gPrintFixedArgs);
iMethodFor(Prototype, gReturnType, Prototype_im_gReturnType);
iMethodFor(Prototype, gIsVarArg, Prototype_im_gIsVarArg);
iMethodFor(Prototype, gHash, Prototype_im_gHash);
iMethodFor(Prototype, gUseVars, Prototype_im_gUseVars);
iMethodFor(Prototype, gDeepDispose, Prototype_im_gDispose);
iMethodFor(Prototype, gVarArg, Prototype_im_gVarArg);
iMethodFor(Prototype, gException, Prototype_im_gException);
iMethodFor(Prototype, gDeepCopy, Prototype_im_gDeepCopy);
ENABLE_THREADER;
LEAVECRITICALSECTION(cs);
return Prototype_c;
}